@extends('frontend/layouts/bootstrap')

@section('content')
<h1>Машины жагсаалт - Document</h1>

{{-- FILTER --}}
<form class="form-inline" style="margin: 0;" action="{{ route('car_balance.main.document_car_list_filter') }}" method="post">
    <table class="table table-bordered">
        <thead style="background-color: #f0f0f0;">
        <tr>
            <th>日付</th>
            <th>オークション</th>
            <th>車体番号</th>
            <th>登録番号</th>
            <th>車検証到着</th>
            <th>抹消日～</th>
            <th>届書送付日～</th>
            <th>自税申告日～</th>
            <th>自賠責解約日～</th>
            <th>Ｒ申請日～</br>Ｒ返還日～</th>
            <th>コメント</th>
            <th>Action</th>
        </tr>
        </thead>

        <tbody>
        <tr>
            <td>
                <input style="width: 70px;" class="input-small" placeholder="日付" type="text" name="purchase_date" id="daterange" value="{{ count($filters['purchase_date']) > 1 ? $filters['purchase_date'][0] .' - '.$filters['purchase_date'][1] : '' }}"/>
            </td>
            <td>
                {{ Form::select('car_auction_id', $car_auction_list, $filters['car_auction_id'], array('class' => 'input-small', 'style' => 'width: 95px;')) }}
                </br><input style="margin-top: 5px; width: 80px;" placeholder="出品番号" type="text" name="lot_no" class="input-small" value="{{ $filters['lot_no'] ? $filters['lot_no'] : '' }}"/>
            </td>
            <td>
                <input id='chassis_no' style="width: 50px;" placeholder="車体番号" type="text" name="chassis_no" class="input-small" value="{{ $filters['chassis_no'] ? $filters['chassis_no'] : '' }}"/>
            </td>
            <td>
                <input style="width: 100px;" placeholder="登録番号" type="text" name="registration_number" class="input-small" value="{{ $filters['registration_number'] ? $filters['registration_number'] : '' }}"/>
            </td>
            <td style="width: 70px;">
                <input id="shakensyo_flag_cb" placeholder="設定" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" name="shakensyo_flag_cb" {{ $filters['shakensyo_flag_cb'] ? 'checked' : '' }}/><label for="shakensyo_flag_cb">設定</label>
            </td>
            <td>
                <input style="width: 70px;" class="datepicker input-small" placeholder="抹消日" title="抹消日" name="burtgel_solih_date" id="burtgel_solih_date" type="text" value="{{ $filters['burtgel_solih_date'] }}" {{ $filters['burtgel_solih'] ? 'disabled' : '' }}>
                </br><input id="burtgel_solih" placeholder="未設定" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" onclick="enableDisable(this.checked, 'burtgel_solih_date')" name="burtgel_solih" {{ $filters['burtgel_solih'] ? 'checked' : '' }}/><label for="burtgel_solih">未設定</label>
            </td>
            <td>
                <input style="width: 70px;" class="datepicker input-small" placeholder="届書送付日" title="届書送付日" name="send_export_erasure_to_transport_company_date" id="send_export_erasure_to_transport_company_date" type="text" value="{{ $filters['send_export_erasure_to_transport_company_date'] }}" {{ $filters['send_export_erasure_to_transport_company'] ? 'disabled' : '' }}>
                </br><input id="send_export_erasure_to_transport_company" placeholder="未設定" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" onclick="enableDisable(this.checked, 'send_export_erasure_to_transport_company_date')" name="send_export_erasure_to_transport_company" {{ $filters['send_export_erasure_to_transport_company'] ? 'checked' : '' }}/><label for="send_export_erasure_to_transport_company">未設定</label>
            </td>
            <td>
                <input style="width: 70px;" class="datepicker input-small" placeholder="自税申告日" title="自税申告日" name="car_tax_cancel_date" id="car_tax_cancel_date" type="text" value="{{ $filters['car_tax_cancel_date'] }}" {{ $filters['car_tax_cancel'] ? 'disabled' : '' }}>
                </br><input id="car_tax_cancel" placeholder="自税申告日" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" onclick="enableDisable(this.checked, 'car_tax_cancel_date')" name="car_tax_cancel" {{ $filters['car_tax_cancel'] ? 'checked' : '' }}/><label for="car_tax_cancel">未設定</label>
            </td>
            <td>
                <input style="width: 75px;" class="datepicker input-small" placeholder="自賠責解約日" title="自賠責解約日" name="car_liability_insurance_cancel_date" id="car_liability_insurance_cancel_date" type="text" value="{{ $filters['car_liability_insurance_cancel_date'] }}" {{ $filters['car_liability_insurance_cancel'] ? 'disabled' : '' }}>
                </br><input id="car_liability_insurance_cancel" placeholder="未設定" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" onclick="enableDisable(this.checked, 'car_liability_insurance_cancel_date')" name="car_liability_insurance_cancel" {{ $filters['car_liability_insurance_cancel'] ? 'checked' : '' }}/><label for="car_liability_insurance_cancel">未設定</label>
            </td>
            <td>
                <input style="width: 70px;" class="datepicker input-small" placeholder="Ｒ申請日" title="Ｒ申請日" name="recycle_application_date" id="recycle_application_date" type="text" value="{{ $filters['recycle_application_date'] }}" {{ $filters['recycle_application'] ? 'disabled' : '' }}>
                </br><input id="recycle_application" placeholder="未設定" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" onclick="enableDisable(this.checked, 'recycle_application_date')" name="recycle_application" {{ $filters['recycle_application'] ? 'checked' : '' }}/><label for="recycle_application">未設定</label>
                <input style="width: 70px;" class="datepicker input-small" placeholder="Ｒ返還日" title="Ｒ返還日" name="recycle_date" id="recycle_date" type="text" value="{{ $filters['recycle_date'] }}" {{ $filters['recycle'] ? 'disabled' : '' }}>
                </br><input id="recycle" placeholder="未設定" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" onclick="enableDisable(this.checked, 'recycle_date')" name="recycle" {{ $filters['recycle'] ? 'checked' : '' }}/><label for="recycle">未設定</label>
            </td>
            <td>
                <input style="width: 50px;" placeholder="コメント" type="text" name="comment" class="input-small" value="{{ $filters['comment'] ? $filters['comment'] : '' }}"/>
            </td>
            <td style="width: 80px;">
                {{ Form::token() }}
                <button type="submit" class="btn">Apply Filter</button>
                <!--                <button type="reset" class="btn" onclick="reset()">Reset</button>-->
                <a class="btn" href="{{ route('car_balance.main.document_car_list') }}?reset=1">Reset</a>
            </td>
        </tr>
        </tbody>
    </table>
</form>

@if ($cars->count())
<div>{{ $cars->getTotal() }} results.</div>
<div class="container-wrapper">
    <div class="fixed-th-table-wrapper">
        <table class="table table-bordered table-condensed table-hover">
            <thead style="background-color: #f0f0f0; white-space:nowrap;">
            <tr>
                <th title="Action">Action</th>
                <th title="Date">日付</th>
                <th title="Auction">オーク会場</th>
                <th title="Auction no">出品番号</th>
                <th title="Car model">車種</th>
                <th title="Car year">年式</th>
                <th title="Chassis number">車体番号</th>
            </tr>
            </thead>
            <tbody style="font-size: 11px; white-space:nowrap;"">
            @foreach($cars as $car)
            <tr>
                <th >
                    <a style="margin-left: 10px;" class="btn btn-primary btn-mini" href="{{ route('car_balance.main.backoffice', $car->id) }}" title="Edit"><i class="icon-edit icon-white"></i></a>
                </th>
                <th>{{ $car->purchase_date }}</th>
                <th>{{ $car->auction_name }}</th>
                <th>{{ $car->lot_no }}</th>
                <th>{{ $car->car_maker }} {{ $car->car_name }}</th>
                <th>{{ $car->car_year }}</th>
                <th>{{ $car->chasis_no; }}</th>
            </tr>
            @endforeach
            </tbody>
        </table>
    </div>
    <div class="scrolled-td-table-wrapper">
        <table class="table table-bordered table-condensed table-hover">
            <thead style="background-color: #f0f0f0; white-space:nowrap;">
            <tr>
                <th title="Action">Action</th>
                <th title="Date">日付</th>
                <th title="Auction">オーク会場</th>
                <th title="Auction no">出品番号</th>
                <th title="Car model">車種</th>
                <th title="Car year">年式</th>
                <th title="Chassis number">車体番号</th>
                <td title="Shakensyo Flag">車検証到着</td>
                <td title="Registration number">登録番号</td>
                <td title="Number Plate Flag">ナンバー到着</td>
                <td title="Day of Cancellation">抹消日</td>
                <td title="Send export erasure to transport company">届書送付日</td>
                <td title="Export erasure image">届書Image</td>
                <td title="FAX sending Date">FAX送付日</td>
                <td title="Car tax amount">自動車税</td>
                <td title="Car tax cancel">自税申告日</td>
                <td title="car tax cancel amount">自税還付金</td>
                <td title="Car liability insurance cancel">自賠責解約日</td>
                <td title="Car liability insurance cancel amount">自賠責還付金</td>
                <td title="Recycle amount">Ｒ預託金</td>
                <td title="Recycle application date">Ｒ申請日</td>
                <td title="Recycle return date">Ｒ返還日</td>
                <td title="Returned recycle">Ｒ返還金</td>
                <td title="Comment">コメント</td>
            </tr>
            </thead>
            <tbody style="font-size: 11px; white-space:nowrap;"">
            @foreach($cars as $car)
            <tr>
                <th >
                    <a style="margin-left: 10px;" class="btn btn-primary btn-mini" href="{{ route('car_balance.main.backoffice', $car->id) }}" title="Edit"><i class="icon-edit icon-white"></i></a>
                </th>
                <th>{{ $car->purchase_date }}</th>
                <th>{{ $car->auction_name }}</th>
                <th>{{ $car->lot_no }}</th>
                <th>{{ $car->car_maker }} {{ $car->car_name }}</th>
                <th>{{ $car->car_year }}</th>
                <th>{{ $car->chasis_no; }}</th>
                <td>
                    @if ($car->shakensyo_flag and $car->burtgel_solih )
                        <span class="badge badge-success"><i class="icon icon-ok"></i></span>
                    @else
                        <input id="shakensyo_flag" placeholder="チェック" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" onclick="setShakensyoFlag(this.checked, {{ $car->id }})" name="shakensyo_flag" {{  $car->shakensyo_flag ? 'checked' : '' }}/>
                    @endif
                </td>
                <td>{{ $car->registration_number; }}</td>
                <td>
                    @if ($car->number_plate_flag != 1 )
                        <span class="badge badge-inverse"><i class="icon icon-off"></i></span>
                    @else
                        @if ($car->number_arrival_flag and $car->fax_export_erasure_to_auction )
                        <span class="badge badge-success"><i class="icon icon-ok"></i></span>
                        @else
                        <input id="number_arrival_flag" placeholder="チェック" type="checkbox" class="input-small" style="margin-bottom: 5px; margin-right: 5px;" onclick="setNumberArrival(this.checked, {{ $car->id }})" name="number_arrival_flag" {{  $car->number_arrival_flag ? 'checked' : '' }}/>
                        @endif
                    @endif
                </td>
                <td>{{ $car->burtgel_solih; }}</td>
                <td>{{ $car->send_export_erasure_to_transport_company; }}</td>
                @if ( $car->mail_export_erasure_to_nmc_upload_flag )
                <td><a target="_blank" style="margin-left: 25px;" class="btn btn-success btn-mini" href="{{route('car_balance.main.display', array('type'=>'export_cert', 'file'=>$car->chasis_no.'.jpg'))}}" title="{{ $car->car_year }}-{{ $car->car_name }}-{{ $car->chasis_no; }}"><i class="icon-zoom-in icon-white"></i></a></td>
                @else
                <td>No image upload</td>
                @endif
                <td>{{ $car->fax_export_erasure_to_auction; }}</td>
                <td style="text-align: right;">{{ ( $car->car_tax_amount == 0 ) ? $car->car_tax_amount :  number_format($car->car_tax_amount, 0); }}</td>
                <td>{{ $car->car_tax_cancel; }}</td>
                <td style="text-align: right;">{{ ( $car->car_tax_cancel_amount == 0 ) ? $car->car_tax_cancel_amount :  number_format($car->car_tax_cancel_amount, 0); }}</td>
                <td>{{ $car->car_liability_insurance_cancel; }}</td>
                <td style="text-align: right;">{{ ( $car->car_liability_insurance_cancel_amount == 0 ) ? $car->car_liability_insurance_cancel_amount :  number_format($car->car_liability_insurance_cancel_amount, 0); }}</td>
                <td style="text-align: right;">{{ ( $car->recycle_amount == 0 ) ? $car->recycle_amount :  number_format($car->recycle_amount, 0); }}</td>
                <td>{{ $car->recycle_application_date; }}</td>
                <td>{{ $car->recycle; }}</td>
                <td style="text-align: right;">{{ ( $car->returned_recycle == 0 ) ? $car->returned_recycle :  number_format($car->returned_recycle, 0); }}</td>
                <td>{{ $car->document_comment; }}</td>
            </tr>
            @endforeach
            </tbody>
        </table>
    </div>
</div>

@include('nimo/domains/car_balance/page')

@else
Хайлтад тохирох үр дүн алга
@endif

@stop


@section('pagestyles')
<link rel="stylesheet" type="text/css" href={{ asset('assets/chosen-bootstrap/chosen.min.css') }} />
<link rel="stylesheet" type="text/css" href={{ asset('assets/bootstrap-daterangepicker/daterangepicker.css') }} />
<link rel="stylesheet" type="text/css" href={{ asset('assets/lightbox/lightbox.css') }} />
<link rel="stylesheet" type="text/css" href={{ asset('assets/bootstrap-datepicker/datepicker.css') }} />
<style type="text/css" media="screen">
    .container-wrapper {
        /* Attach fixed-th-table to this container,
           in order to layout fixed-th-table
           in the same way as scolled-td-table" */
        position: relative;

        /* Truncate fixed-th-table */
        overflow: hidden;
        width: 1170px;
    }

    .fixed-th-table-wrapper td,
    .fixed-th-table-wrapper th,
    .scrolled-td-table-wrapper td,
    .scrolled-td-table-wrapper th {
        /* Set background to non-transparent color
           because two tables are one above another.
         */
        background: white;
    }
    .fixed-th-table-wrapper {
        /* Make table out of flow */
        position: absolute;
    }
    .fixed-th-table-wrapper th {
        /* Place fixed-th-table th-cells above
           scrolled-td-table td-cells.
         */
        position: relative;
        z-index: 1;
    }
    .scrolled-td-table-wrapper td {
        /* Place scrolled-td-table td-cells
           above fixed-th-table.
         */
        position: relative;
    }
    .scrolled-td-table-wrapper {
        /* Make horizonal scrollbar if needed */
        overflow-x: scroll;
    }

</style>
@stop

@section('pagescripts')
<!--page specific plugin scripts-->
<script type="text/javascript" src={{ asset('assets/chosen-bootstrap/chosen.jquery.min.js') }}></script>
<script type="text/javascript" src={{ asset('assets/bootstrap-daterangepicker/date.js') }} ></script>
<script type="text/javascript" src={{ asset('assets/bootstrap-daterangepicker/daterangepicker.js') }}></script>
<script type="text/javascript" src={{ asset('assets/bootstrap-datepicker/datepicker.js') }}></script>
<script type="text/javascript" src={{ asset('assets/lightbox/lightbox-2.6.min.js') }}></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[name="purchase_date"]').daterangepicker({
            format:"yyyy/MM/dd"
        });
        $( ".datepicker" ).datepicker({
//            startDate: "-3m",
//            endDate: "+3m",
//            minDate: null,
//            maxDate: null,
            defaultDate: "+0d",
            format: "yyyy/mm/dd",
            autoclose: true
        });
        $('#chassis_no').focus();
    });

    function enableDisable(bEnable, textBoxID) {
        document.getElementById(textBoxID).disabled = bEnable;
        document.getElementById(textBoxID).value = "";
    }

    function setShakensyoFlag(bEnable, carId) {

        var request = $.ajax({
            url: "{{ route('car_balance.main.set_shakensyo') }}",
            type: "GET",
            data: { carId : carId, status: bEnable},
            dataType: "JSON"
        });

        request.done(function(result) {
            console.log(result.status);
        });

    }

    function setNumberArrival(bEnable, carId) {
        var request = $.ajax({
            url: "{{ route('car_balance.main.set_number_arrival') }}",
            type: "GET",
            data: { carId : carId, status: bEnable },
            dataType: "JSON"
        });

        request.done(function(result) {
            console.log(result.status);
        });
    }

function resetFilter() {
    console.log('fff');
}
</script>
@stop